#include <CpLog.h>
#include "CpPolynom1D.h"
#include <TMath.h>
#include <TF1.h>

ClassImp(CpPolynom1D);

//______________________________________________________________________________
CpPolynom1D::CpPolynom1D(): TObject() {
//
// Constructor
//

  CpDebug(CpLog::kDebug + 5, "<-");
  CpDebug(CpLog::kDebug + 5, "->");

}

//______________________________________________________________________________
CpPolynom1D::~CpPolynom1D() {
//
// Destructor.
//
  CpDebug(CpLog::kDebug + 5, "<-");
  CpDebug(CpLog::kDebug + 5, "->");
}


//________________________________________________________________________________________________________________
Int_t CpPolynom1D::GetNumberOfParameters(Int_t grade) {
//
// Gets Number of parameters
//
//   CpDebug(CpLog::kDebug+5,"<-");
  switch (grade) {
  case 0:  return 1;
  case 1:  return 2;
  case 2:  return 3;
  case 3:  return 4;
  case 4:  return 5;
  case 5:  return 6;
  case 6:  return 7;
  case 7:  return 8;
  case 8:  return 9;
  case 9:  return 10;
  case 10: return 11;
  case 11: return 12;
  default : return -1;

  }

//   CpDebug(CpLog::kDebug+5,"->");


}



Double_t CpPolynom1D::DoPolynom0(Double_t* x, Double_t* par) {
  // x^0
  Double_t r = par[0] + x[0] * 0;
  return r;
}


Double_t CpPolynom1D::DoPolynom1(Double_t* x, Double_t* par) {
  Double_t r = DoPolynom0(x, par);

  // x
  r += par[1] * TMath::Power(x[0], 1);
  return r;
}


Double_t CpPolynom1D::DoPolynom2(Double_t* x, Double_t* par) {
  Double_t r = DoPolynom1(x, par);

  // x^2
  r += par[2] * TMath::Power(x[0], 2);
  return r;
}


Double_t CpPolynom1D::DoPolynom3(Double_t* x, Double_t* par) {
  Double_t r = DoPolynom2(x, par);

  // x^3
  r += par[3] * TMath::Power(x[0], 3);
  return r;
}
Double_t CpPolynom1D::DoPolynom4(Double_t* x, Double_t* par) {
  Double_t r = DoPolynom3(x, par);

  // x^4
  r += par[4] * TMath::Power(x[0], 4);
  return r;
}
Double_t CpPolynom1D::DoPolynom5(Double_t* x, Double_t* par) {
  Double_t r = DoPolynom4(x, par);

  // x^5
  r += par[5] * TMath::Power(x[0], 5);
  return r;
}
Double_t CpPolynom1D::DoPolynom6(Double_t* x, Double_t* par) {
  Double_t r = DoPolynom5(x, par);

  // x^6
  r += par[6] * TMath::Power(x[0], 6);
  return r;
}
Double_t CpPolynom1D::DoPolynom7(Double_t* x, Double_t* par) {
  Double_t r = DoPolynom6(x, par);

  // x^7
  r += par[7] * TMath::Power(x[0], 7);
  return r;
}
Double_t CpPolynom1D::DoPolynom8(Double_t* x, Double_t* par) {
  Double_t r = DoPolynom7(x, par);

  // x^8
  r += par[8] * TMath::Power(x[0], 8);
  return r;
}
Double_t CpPolynom1D::DoPolynom9(Double_t* x, Double_t* par) {
  Double_t r = DoPolynom8(x, par);

  // x^9
  r += par[9] * TMath::Power(x[0], 9);
  return r;
}
Double_t CpPolynom1D::DoPolynom10(Double_t* x, Double_t* par) {
  Double_t r = DoPolynom9(x, par);

  // x^10
  r += par[10] * TMath::Power(x[0], 10);
  return r;
}
